package come.example.pagetransformer.utils;

import android.support.design.internal.BottomNavigationItemView;
import android.support.design.internal.BottomNavigationMenuView;
import android.support.design.widget.BottomNavigationView;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class BottomNavigationViewHolder {

    public static void disableCalculateTextScale(BottomNavigationView view) {
        BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
        try {
            for (int i = 0; i < menuView.getChildCount(); i++) {
                BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
                Method[] methods = item.getClass().getDeclaredMethods();
                for (int j = 0; j < methods.length; j++) {
                    if ("calculateTextScaleFactors".equalsIgnoreCase(methods[j].getName())) {
                        methods[j].setAccessible(true);
                        methods[j].invoke(item, 1.0f, 1.0f);
                        methods[j].setAccessible(false);
                        continue;
                    }
                }
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
